package com.zfei.gfb.request;

import cn.hutool.core.lang.Validator;
import com.zfei.gfb.bean.Const;
import com.zfei.gfb.util.ObjUtil;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;


/**
 * @author fgh
 */
public class GfbUserAddRequest {

    // 手机号
    @ApiModelProperty(value = "联系电话（用户名）", required = true)
    private String phone;
    // 用户名
    @ApiModelProperty(value = "管理员名称", required = true)
    private String name;
    // 密码
    @ApiModelProperty(value = "密码", required = true)
    private String password;
    @ApiModelProperty(value = "确认密码", required = true)
    private String confirmPassword;
    // 管理员级别，1: 镇，2：村
    @ApiModelProperty(value = "管理员级别，1: 镇，2：村", required = true)
    private Integer type;
    @ApiModelProperty(value = "所属村", required = false)
    private String villagerName;

    public void setPhone(String value) {
        this.phone = value;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setName(String value) {
        this.name = value;
    }

    public String getName() {
        return this.name;
    }

    public void setPassword(String value) {
        this.password = value;
    }

    public String getPassword() {
        return this.password;
    }

    public void setType(Integer value) {
        this.type = value;
    }

    public Integer getType() {
        return this.type;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getVillagerName() {
        return villagerName;
    }

    public void setVillagerName(String villagerName) {
        this.villagerName = villagerName;
    }

    public void checkInsertNull() {
        if (ObjUtil.anyNull(phone, name, type, password, confirmPassword)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(StringUtils.isAnyBlank(phone, name, password, confirmPassword)){
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(password.length() < 8 || password.length() > 16){
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(name.length() > Const.NAME_LENGTH){
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if(!Validator.isGeneral(password)){
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if (!password.equals(confirmPassword)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
//        if(!Validator.isMobile(phone)){
//            throw new StatusException(Status.INVALID_ARGUMENT);
//        }
        if (type != Const.GFB_VILLAGE_MANAGER && type != Const.GFB_TOWN_MANAGER) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if ((type == Const.GFB_VILLAGE_MANAGER && villagerName == null)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if ((type == Const.GFB_TOWN_MANAGER && villagerName != null)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
    }
}

